<?php
namespace backend\models;

use Yii;
use yii\base\Model;
use yii\base\Exception;

class QueryForm extends Model
{
	public $barcode;

	public function formName()
    {
        return '';
    }

	public function rules()
	{
		return [
			['barcode', 'required'],
			['barcode', 'string']
		];
	}

	public function check()
	{
	    $source = '34';
	    $barcode = $this->barcode;
	    $timestamp = time();
	    $key = 'HXJYPG';
	    $validate = md5($source . $barcode . $timestamp . $key);
	    $channelId = '952';
	    $url = Yii::$app->params['hxgrm_url'] . "/hxhms/hapi/v1/genedetection/detectionprocess/get?source=" . $source . "&timestamp=" . $timestamp . "&validate=" . $validate . "&barcode=" . $barcode . "&channelId=" . $channelId;
	    $ch = curl_init();
	    curl_setopt($ch, CURLOPT_URL, $url);
	    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
	    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); 
	    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	    $output = curl_exec($ch);
	    curl_close($ch);
	    $data = json_decode($output, true);
	    if ($data['ret'] == 0) {
	        $msg = [];
	        $info = [];
	        foreach ($data['resultList'] as $val) {
	            $info['status'] = $val['detectionProcessStatus'];
	            $info['name'] = $val['detectionProcessName'];
	            $info['time'] = date('Y-m-d H:i:s', substr($val['createDate']['time'], 0, 10));
	            array_push($msg, $info);
	        }
	        $re = [
	            'flag' => true,
	            'msg' => $msg
	        ];
	    } else {
	        $re = [
	            'flag' => false,
	            'msg' => $data['msg']
	        ];
	    }

	    return $re;
	}



}    